<?php
/**
 * Created by PhpStorm.
 * @auth:Eddy
 * @527084800@qq.com
 * Date: 18-4-10
 */
$http = new swoole_http_server("0.0.0.0", 9501);

$http->set(
    [
        'enable_static_handler' => true,
        'document_root' => "/usr/share/nginx/html/blog/public/static/live",
    ]
);
$http->on('WorkerStart',function(swoole_server $server, $worker_id){

    // 定义应用目录
    define('APP_PATH', __DIR__ . '/../application/');
    // 加载框架引导文件
    require __DIR__ . '/../thinkphp/base.php';

});
$http->on('request', function($request, $response) use ($http) {

    ## 处理一些全局数组
    $_GET = [];
    if (isset($request->get)){
        foreach ($request->get as $k => $v){
            $_GET[$k] = $v;
        }
    }

    $_POST = [];
    if (isset($request->post)){
        foreach ($request->post as $k => $v){
            $_POST[$k] = $v;
        }
    }

    if (isset($request->header)){
        foreach ($request->header as $k => $v){
            $_SERVER[strtoupper($k)] = $v;
        }
    }
    if (isset($request->request)){
        foreach ($request->request as $k => $v){
            $_SERVER[strtoupper($k)] = $v;
        }
    }
    ## 处理一些全局数组  END
    ob_start();
    // 执行应用并响应
    think\Container::get('app', [APP_PATH])
        ->run()
        ->send();
    $test = ob_get_contents();
    ob_end_clean();

    $response->end($test);
});

$http->start();
